//
// Created by dxyinme on 2021/10/8.
//

#ifndef VSORT_SORT_FILE_H
#define VSORT_SORT_FILE_H

#include "serializer.h"
#include <string>
#include <vector>

namespace Vsort {
namespace FileSort {

static const char * WORK_PLACE = "_workplace";

class SortFile {
private:
  std::string filename;
  Serializer* serializer_{nullptr};
  std::vector<std::string> map_filenames;
  void MapFile();
  void ReduceFile();
  void MergeFiles(size_t i, size_t j);
  void SortSingleFile(const std::string& file);
public:
  explicit SortFile() = default;
  explicit SortFile(const std::string& file);
  void SetSerializer(Serializer* serializer);
  void SortFileTo(const std::string& target_filename);
  ~SortFile();
};

}
}

#endif //VSORT_SORT_FILE_H
